package com.intellagric.controller.module.ift_ctrl_equipment;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.CtrlEquipmentVo;
import com.intellagric.pojo.IftCtrlEquipment;
import com.intellagric.service.iftmonitor.ift_ctrl_equipment.CtrlEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/21
 * @DESC： 控制设备管理
 */
@Controller
public class CtrlEquipmentController {

    @Autowired
    private CtrlEquipmentService ctrlEquipmentService;

    /**
     * 添加控制设备信息
     * @Param ctrlEquipment
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/add")
    @ResponseBody
    public ResponseMessage add(IftCtrlEquipment ctrlEquipment) {
        ctrlEquipment.setId(UUID.randomUUID().toString().replaceAll("-",""));
        ctrlEquipment.setCreateDate(new Date());
        ctrlEquipment.setUpdateDate(new Date());
        return ctrlEquipmentService.addCtrlEquipment(ctrlEquipment);
    }


    /**
     * 删除控制设备信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return ctrlEquipmentService.deleteCtrlEquipment(id);
    }

    /**
     * 修改控制设备信息
     * @Param ctrlEquipment
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/edit")
    @ResponseBody
    public ResponseMessage edit(IftCtrlEquipment ctrlEquipment) {
        ctrlEquipment.setCreateDate(null);
        ctrlEquipment.setUpdateDate(new Date());
        return ctrlEquipmentService.editCtrlEquipment(ctrlEquipment);
    }

    /**
     * 查询控制设备信息
     * @return IftCtrlEquipment
     */
    @RequestMapping("/ctrlequipment/{id}")
    @ResponseBody
    public IftCtrlEquipment get(@PathVariable String id) {
        return ctrlEquipmentService.getCtrlEquipmentById(id);
    }

    /**
     * 查询控制设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return ctrlEquipmentService.getCtrlEquipmentList();
    }

    /**
     * 多条件查询控制设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(CtrlEquipmentVo ctrlEquipmentVo) {
        return ctrlEquipmentService.getCtrlEquipmentListByVo(ctrlEquipmentVo);
    }

    /**
     * 分页查询控制设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return ctrlEquipmentService.getCtrlEquipmentPage(page,limit);
    }


}
